﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class UIHomeHandler : MonoBehaviour {

    //UI界面的引用
    private GameObject SZmenu;
    private GameObject SMmenu;
    private GameObject Shop;

    //本局分数
    private Text Newscore;
    private Text Highscore;

    //玩家金币数
    private Text Gold;

    void Start()
    {
        SZmenu = GameObject.Find("Canvas/SZmenu");
        SZmenu.SetActive(false);
        SMmenu = GameObject.Find("Canvas/SMmenu");
        SMmenu.SetActive(false);
        Shop = GameObject.Find("Shop");
        Shop.SetActive(false);

        Newscore = GameObject.Find("Newscore").GetComponent<Text>();
        Highscore = GameObject.Find("Highscore").GetComponent<Text>();
        Gold = GameObject.Find("Gold/Text").GetComponent<Text>();

    }

    void Update()
    {
         Newscore.text = PlayerMove.score.ToString();
         if (PlayerPrefs.GetInt("score") > int.Parse(Highscore.text))
         {
                Highscore.text = PlayerMove.score.ToString();
         }
         Gold.text = PlayerMove.gold.ToString();
    }


    //开始游戏按钮，切换界面
    public void StartGame()
    {
        //Application.LoadLevel(1);
        SceneManager.LoadScene(1);
    }

    //点击设置按钮，弹出设置菜单
    public void Setting()
    {
        SZmenu.SetActive(true);
    }
    //关闭设置菜单
    public void CloseSetting()
    {
        SZmenu.SetActive(false);
    }
    

    //打开说明菜单
    public void ShouMing()
    {
        SMmenu.SetActive(true);
    }
    //关闭游戏说明菜单
    public void CloseShouMing()
    {
        SMmenu.SetActive(false);
    }

    //打开商店
    public void Shopping()
    {
        Shop.SetActive(true);
    }
    //关闭商店
    public void CloseShop()
    {
        Shop.SetActive(false);
    }

    /// <summary>
    /// 退出游戏
    /// </summary>
    public void Quit()
    {
        Application.Quit();
    }

   
}
